package classes.view.component
{
	import classes.controller.EClick;
	
	import com.greensock.TweenLite;
	import com.greensock.easing.Quart;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class SortContainer extends Sprite
	{
		private var _sort_numbering:Sprite;
		private var _sort_emptyroom:Sprite;
		
		public function SortContainer()
		{
			super();
			setLayOut();
			defaultSetting();
			initListener();
		}
		private function setLayOut():void
		{
			this._sort_numbering		=	this.getChildByName('sort_btn_0')	as Sprite;
			this._sort_emptyroom		=	this.getChildByName('sort_btn_1')	as Sprite;
		}
		private function defaultSetting():void
		{
			this._sort_numbering.buttonMode = true;
			this._sort_emptyroom.buttonMode = true;
			this._sort_numbering.mouseEnabled = false;
			this._sort_emptyroom.alpha = 0.6;
		}
		private function initListener():void
		{
			this._sort_numbering.addEventListener(MouseEvent.MOUSE_OVER,	onMouseOverHandler);
			this._sort_emptyroom.addEventListener(MouseEvent.MOUSE_OVER,	onMouseOverHandler);
		}
		private function onMouseOverHandler(e:MouseEvent):void
		{
			e.currentTarget.addEventListener(MouseEvent.MOUSE_OUT,	onMouseOutHandler);
			e.currentTarget.addEventListener(MouseEvent.CLICK,		onClickHandler);
			TweenLite.to(e.currentTarget, 0.3,  {alpha:1, ease:Quart.easeOut});
		}
		private function onMouseOutHandler(e:MouseEvent):void
		{
			e.currentTarget.removeEventListener(MouseEvent.MOUSE_OUT,	onMouseOutHandler);
			TweenLite.to(e.currentTarget, 0.3,  {alpha:0.6, ease:Quart.easeOut});
		}
		private function onClickHandler(e:MouseEvent):void
		{
			e.currentTarget.removeEventListener(MouseEvent.CLICK,		onClickHandler);
			if(e.currentTarget == this._sort_emptyroom){
				if(this._sort_emptyroom.hasEventListener(MouseEvent.MOUSE_OUT)) this._sort_emptyroom.removeEventListener(MouseEvent.MOUSE_OUT,	onMouseOutHandler);
				this._sort_numbering.mouseEnabled = true;
				this._sort_emptyroom.mouseEnabled = false;
				this._sort_emptyroom.alpha = 1;
				TweenLite.to(_sort_numbering, 0.3,  {alpha:0.6, ease:Quart.easeOut});
				dispatchEvent(new EClick('emptyRoom', EClick.EVENT_CLICK));
			}else{
				if(this._sort_numbering.hasEventListener(MouseEvent.MOUSE_OUT)) this._sort_numbering.removeEventListener(MouseEvent.MOUSE_OUT,	onMouseOutHandler);
				this._sort_emptyroom.mouseEnabled = true;
				this._sort_numbering.mouseEnabled = false;
				TweenLite.to(_sort_emptyroom, 0.3,  {alpha:0.6, ease:Quart.easeOut});
				this._sort_numbering.alpha = 1;
				dispatchEvent(new EClick('numbering', EClick.EVENT_CLICK));
			}
		}
	}
}